//
//  ShopBookHeader.m
//  PigMarket
//
//  Created by 张敬 on 2019/8/19.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "ShopBookHeader.h"

@implementation ShopBookHeader

#pragma mark - lifecycle methods

- (void)setupUI
{
    [self addSubview:self.bgIcon];
    [self addSubview:self.bgView];
    
    [self.bgView addSubview:self.tipIcon];
    [self.bgView addSubview:self.saleTipLab];
    [self.bgView addSubview:self.saleLab];
    [self.bgView addSubview:self.profitsLab];
    [self.bgView addSubview:self.tiplogo];
    [self.bgView addSubview:self.profitsTipLab];
    
}


- (void)setupLayout
{
    self.height = 220 + TJ_StatusBarHeight;
    
    {
        _bgIcon.size = CGSizeMake(KScreenWidth, TJ_StatusBarHeight + 177);
        _bgIcon.mj_x = _bgIcon.mj_y = 0;
    }
    
    {
        _bgView.size = CGSizeMake(KScreenWidth - 30, 126);
        _bgView.mj_x = 15;
        _bgView.mj_y = 63 + TJ_StatusBarHeight;
    }
    
    
    {
        _saleTipLab.mj_x = 0;
        _saleTipLab.mj_y = 38;
        _saleTipLab.size = CGSizeMake(_bgView.width/2.0, 21);
    }
    
    
    {
        _saleLab.size = CGSizeMake(_bgView.width/2.0, 22);
        _saleLab.mj_x = 0;
        _saleLab.mj_y = _saleTipLab.bottom + 2;
    }
    
    
    {
        _profitsTipLab.frame = _saleTipLab.frame;
        _profitsTipLab.mj_x = _saleTipLab.right;
    }

    
    {
        _profitsLab.frame = _saleLab.frame;
        _profitsLab.mj_x = _saleLab.right;
    }
    
    {
        _tipIcon.size = CGSizeMake(16, 16);
        _tipIcon.mj_x = _profitsLab.right - 60;
        _tipIcon.mj_y = _profitsLab.top +3;
    }
    
    {
        _tiplogo.size = CGSizeMake(163, 33);
        _tiplogo.mj_x =  _tipIcon.right - _tiplogo.width;
        _tiplogo.mj_y = _tipIcon.bottom +5;
    }
    
}

#pragma mark - setter methods


#pragma mark - getter methods

- (UIImageView *)bgIcon{
    
    if (!_bgIcon) {
        _bgIcon = [UIImageView new];
        _bgIcon.image = [UIImage imageNamed:@"screen_book_bg"];
    }
    return _bgIcon;
}


- (UIImageView *)tipIcon{
    
    if (!_tipIcon) {
        _tipIcon = [[UIImageView alloc] init];
        _tipIcon.image = [UIImage imageNamed:@"meat_shop_riskwarning"];
        _tipIcon.isNeedAnimation = YES;
        
        @weakify(self);
        __block BOOL checked = NO;
        _tipIcon.tapBlock = ^{
            @strongify(self);
            checked = !checked;
            if (checked) {
                
                [UIView animateWithDuration:0.5 animations:^{
                    self.tiplogo.alpha = 1;
                }];
                
            }else{
                
                [UIView animateWithDuration:0.5 animations:^{
                    self.tiplogo.alpha = 0;
                }];
            }
        };
    }
    return _tipIcon;
}


- (UIView *)bgView{
    
    if (!_bgView) {
        _bgView = [UIView makeViewBgColor:KWhiteColor cornerRadius:8];
        _bgView.layer.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0].CGColor;
        _bgView.layer.shadowColor = [UIColor colorWithRed:217/255.0 green:226/255.0 blue:233/255.0 alpha:0.5].CGColor;
        _bgView.layer.shadowOffset = CGSizeMake(0,5);
        _bgView.layer.shadowOpacity = 1;
        _bgView.layer.shadowRadius = 12;
    }
    return _bgView;
}


- (UILabel *)saleTipLab{
    
    if (!_saleTipLab) {
        _saleTipLab = [UILabel makeLabelWithText:@"累计总销售额(元）" textColor:UIColorFromRGB(0x808080) font:mFont(12) textAliment:1];
    }
    return _saleTipLab;
}


- (UILabel *)saleLab{
    
    if (!_saleLab) {
        _saleLab = [UILabel makeLabelWithText:@"" textColor:UIColorFromRGB(0x333333) font:mFont(20) textAliment:1];
    }
    return _saleLab;
}


- (UIImageView *)tiplogo{
    
    if (!_tiplogo) {
        _tiplogo = [UIImageView makeImageByImageName:@"shop_books_tip" cornerRadius:0];
        _tiplogo.alpha = 0;
    }
    return _tiplogo;
}


- (UILabel *)profitsTipLab{
    
    if (!_profitsTipLab) {
        _profitsTipLab = [UILabel makeLabelWithText:@"累计利润(元)" textColor:UIColorFromRGB(0x808080) font:mFont(12) textAliment:1];
    }
    return _profitsTipLab;
}


- (UILabel *)profitsLab{
    
    if (!_profitsLab) {
        _profitsLab = [UILabel makeLabelWithText:@"" textColor:UIColorFromRGB(0x333333) font:mFont(20) textAliment:1];
    }
    return _profitsLab;
}


@end
